package com.fieldchain.ex.fa100.utils.chart.utils.zb;

import android.graphics.Color;

import com.fieldchain.ex.fa100.bean.kline.KLineBean;
import com.fieldchain.ex.fa100.bean.kline.WREntity;
import com.github.mikephil.charting.data.CombinedData;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by biyunlong
 * Email: 1225198434@qq.com
 * Data:  2018/10/16
 */
public class WrParse {
    private int c1 = Color.parseColor("#ffcc00");
    private int c2 = Color.parseColor("#0090f7");
    private int c3 = Color.parseColor("#ffffff");

    private ZbDataParse dataParse=new ZbDataParse();
    public CombinedData getData(List<List<String>> list) {
        ArrayList<KLineBean> datas = ZbDataParse.getKlineList(list);

        ArrayList l1 = new ArrayList<>();
        ArrayList l2 = new ArrayList<>();
        ArrayList l3 = new ArrayList<>();

        WREntity wrEntity13 = new WREntity(datas, 13);
        WREntity wrEntity34 = new WREntity(datas, 34);
        WREntity wrEntity89 = new WREntity(datas, 89);


        for (int i = 0; i < wrEntity13.getWRs().size(); i++) {
            l1.add(new Entry(i,wrEntity13.getWRs().get(i)));
            l2.add(new Entry(i,wrEntity34.getWRs().get(i)));
            l3.add(new Entry(i,wrEntity89.getWRs().get(i)));


        }

        LineData lineData = new LineData();
        LineDataSet lineSet1 = new LineDataSet(l1, "");
        LineDataSet lineSet2 = new LineDataSet(l2, "");
        LineDataSet lineSet3 = new LineDataSet(l3, "");
        initLindata(lineSet1, c1);
        initLindata(lineSet2, c2);
        initLindata(lineSet3, c3);

        lineData.addDataSet(lineSet1);
        lineData.addDataSet(lineSet2);
        lineData.addDataSet(lineSet3);

        CombinedData combinedData = new CombinedData();
        combinedData.setData(lineData);
        combinedData.setData(dataParse.getEptData(l1.size()));

        return combinedData;
    }

    public void initLindata(LineDataSet dataSet, int color) {
        dataSet.setColor(color);
        dataSet.setHighlightEnabled(false);
        dataSet.setHighlightLineWidth(1f);
        dataSet.setHighLightColor(c3);
        dataSet.setDrawValues(false);
        dataSet.setDrawCircles(false);
    }

}
